package com.cryptoneedle.garden.entity.source.metadata;


import cn.hutool.v7.core.bean.BeanUtil;
import com.bubbles.engine.data.core.entity.BaseEntity;
import com.cryptoneedle.garden.enums.SourceCollectFrequency;
import com.cryptoneedle.garden.key.DatabaseKey;
import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import lombok.experimental.Accessors;
import org.hibernate.annotations.Comment;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import java.util.Date;

/**
 * <p>description: 源数据源-数据库 </p>
 *
 * @author CryptoNeedle
 * @date 2025-06-19
 */
@Getter
@Setter
@Accessors(chain = true)
@NoArgsConstructor
@AllArgsConstructor
@Entity
@EntityListeners(AuditingEntityListener.class)
@Table(schema = "public", name = "source_database")
@IdClass(DatabaseKey.class)
@Comment("源数据源-数据库")
public class SourceDatabase extends BaseEntity {

    @Id
    @Comment("源数据源-目录名称")
    private String catalogName;
    @Id
    @Comment("源数据源-数据库名称")
    private String databaseName;

    @Comment("统计信息-表数量")
    private Long tableCount;
    @Comment("统计信息-视图数量")
    private Long viewCount;
    @Comment("统计信息-列数量")
    private Long columnCount;
    @Comment("统计信息-约束数量")
    private Long constraintCount;
    @Comment("统计信息-索引数量")
    private Long indexCount;
    @Comment("统计信息-统计时间")
    private Date statisticDt;

    @Comment("源数据源-Doris目录编码")
    private String dorisCatalogName;
    @Comment("源数据源-默认系统编码")
    private String defaultSystemCode;
    @Comment("源数据源-默认采集频率")
    @Enumerated(EnumType.STRING)
    private SourceCollectFrequency defaultCollectFrequency;
    @Comment("源数据源-启用数据库")
    private Boolean enabled;

    /**
     * Key
     */

    public DatabaseKey databaseKey() {
        return BeanUtil.copyProperties(this, DatabaseKey.class);
    }
}